<?php

session_start();
require_once '../data/connect.class.php';

class SmtpOpt {
	
	var $connection;
	function SmtpOpt($conn) {
		$this->connection = $conn;
	}
	function createSmtp($smtp_name,$from_addr,$smtp_host,$smtp_port,$smtp_user_name,$smtp_password,$smtp_status) {

		$sql = "insert into admin_smtp_server(name,from_addr,host,port,user_name,password,status) ";
		$sql .= "values('";
		$sql .= $smtp_name;
		$sql .= "','";
		$sql .= $from_addr;
		$sql .= "','";
		$sql .= $smtp_host;
		$sql .= "',";
		$sql .= $smtp_port;
		$sql .= ",'";
		$sql .= $smtp_user_name;
		$sql .= "','";
		$sql .= $smtp_password;
		$sql .= "',";
		$sql .= $smtp_status;
		$sql .= ")";
		echo $sql;
		$this->connection->execute($sql);
	}
	
	function delSmtp($id) {
		$param = array('id'=>$id);
		$this->connection->delSql('admin_smtp_server',$param);
	}
	
	function updateSmtp($id,$array) {
		$this->connection->updateSql('admin_smtp_server',$array,"id=".$id);
	}
}

$connect = new Connect("localhost","root","","email");
$smtpOpt = new SmtpOpt($connect);
$opt=$_POST['opt'];

if (isset($opt)) {
	if ($opt=='addSmtp') {
		$smtp_name = $_POST['smtp_name'];
        $from_addr = $_POST['from_addr'];
        $smtp_host = $_POST['smtp_host'];
        $smtp_port = $_POST['smtp_port'];
        $smtp_user_name = $_POST['smtp_user_name'];
        $smtp_password = $_POST['smtp_password'];
        $smtp_status = $_POST['smtp_status'];
        $smtpOpt->createSmtp($smtp_name,$from_addr,$smtp_host,$smtp_port,$smtp_user_name,$smtp_password,$smtp_status);
	}
	if ($opt=='delSmtp') {
		$id = $_POST['id'];
		$smtpOpt->delSmtp($id);
	}
	if ($opt=="updateSmtp") {
		$id = $_POST['id'];
		$smtp_name = $_POST['smtp_name'];
        $from_addr = $_POST['from_addr'];
        $smtp_host = $_POST['smtp_host'];
        $smtp_port = $_POST['smtp_port'];
        $smtp_user_name = $_POST['smtp_user_name'];
        $smtp_password = $_POST['smtp_password'];
        $smtp_status = $_POST['smtp_status'];

        $array = array("name"=>$smtp_name,
                       "from_addr"=>$from_addr,
                       "host"=>$smtp_host,
                       "port"=>$smtp_port,
                       "user_name"=>$smtp_user_name,
                       "password"=>$smtp_password,
                       "status"=>$smtp_status);
        $smtpOpt->updateSmtp($id,$array);
	}
}

?>